
package com.lzxr.test.servlet;

import com.lzxr.test.utils.ImageVerificationCode;
import java.awt.image.BufferedImage;
import java.io.IOException;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

public class QrServlet extends HttpServlet {
    public QrServlet() {
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ImageVerificationCode ivc = new ImageVerificationCode();
        BufferedImage image = ivc.getImage();
        req.getSession().setAttribute("code", ivc.getText());
        ivc.output(image, resp.getOutputStream());
    }
}
